from Factors.General import *


def CalcCapitalAllocationFactor(database, instruments, datetime1, datetime2, update=False):

    # ---Last File---
    # Asset to Equity
    CalcFundamentalFactor(database, instruments, datetime1, datetime2,
                          factorName="Leverage",
                          fields=["TotalAsset", "TotalEquity"],
                          callback=ConsensusDivideCallback,
                          params={"Numerator": "TotalAsset", "Denominator": "TotalEquity"},
                          update=update)
    # 资产负债率
    CalcFundamentalFactor(database, instruments, datetime1, datetime2,
                          factorName="DebtToAsset",
                          fields=["TotalLiab", "TotalAsset"],
                          callback=ConsensusDivideCallback,
                          params={"Numerator": "TotalLiab", "Denominator": "TotalAsset"},
                          update=update)
    #
    CalcFundamentalFactor(database, instruments, datetime1, datetime2,
                          factorName="CurrentAssetToAsset",
                          fields=["CurrentAsset", "TotalAsset"],
                          callback=ConsensusDivideCallback,
                          params={"Numerator": "CurrentAsset", "Denominator": "TotalAsset"},
                          update=update)
    #
    CalcFundamentalFactor(database, instruments, datetime1, datetime2,
                          factorName="CurrentRatio",
                          fields=["CurrentAsset", "CurrentLiab"],
                          callback=ConsensusDivideCallback,
                          params={"Numerator": "CurrentAsset", "Denominator": "CurrentLiab"},
                          update=update)